package com;


//import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.defaultPage.errorPage.MyCustomizer;

@EnableTransactionManagement
@SpringBootApplication
// @ComponentScan(basePackages = "com")
public class Application {
//    private static Logger logger = Logger.getLogger(Application.class);

    // DataSource配置
    // @Bean
    // @ConfigurationProperties(prefix = "spring.datasource")
    // public DataSource dataSource() {
    // return new org.apache.tomcat.jdbc.pool.DataSource();
    // }
    //
    // // 提供SqlSeesion
    // @Bean
    // public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
    //
    // SqlSessionFactoryBean sqlSessionFactoryBean = new
    // SqlSessionFactoryBean();
    // sqlSessionFactoryBean.setDataSource(dataSource());
    //
    // PathMatchingResourcePatternResolver resolver = new
    // PathMatchingResourcePatternResolver();
    //
    // sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
    //
    // return sqlSessionFactoryBean.getObject();
    // }
    //
    // @Bean
    // public PlatformTransactionManager transactionManager() {
    // return new DataSourceTransactionManager(dataSource());
    // }

    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        // TomcatEmbeddedServletContainerFactory factory = new
        // TomcatEmbeddedServletContainerFactory();
        JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
        factory.setPort(8089);
        factory.setContextPath("/springBoot");
//        factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"));
        return factory;
    }

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return new MyCustomizer();
    }

    /**
     * Main Start
     */
    public static void main(String[] args) {
        // SpringApplication springApplication = new
        // SpringApplication(Application.class);
        System.out.println("fs");
        SpringApplication.run(Application.class, args);
//        logger.info("============= SpringBoot Start Success =============");
    }

}